// pages/admin/adminSetting/setting/setting.js
const app = getApp();
import Api from '../../../../utils/http'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userinfo:'',//个人信息
    userInfo:'',//切换用户信息
  },
  //跳转绑定手机号
  toChangeBindTel: function () {
    wx.navigateTo({
      url: '/pages/user/user/bindTelStepOne/bindTelStepOne',
    })
  },
  //跳转身份验证
  toIdentityAuth: function () {
    if (this.data.userinfo.verification_manage==1) {
      wx.showToast({
        title: '身份已认证',
        icon:'none',
        duration:2000
      })
    }else{
      wx.navigateTo({
        url: '/pages/user/user/identityAuth/identityAuth',
      })
    }
  },
  //变更管理员
  administrators:function(){
    wx.navigateTo({
      url: '/pages/recycling/changeExplain/changeExplain',
    })
  },
  // //退出
  // logoutWxApp: function () {
  //     wx.showModal({
  //       title: '提示',
  //       content: '确定退出',
  //       success (res) {
  //       if (res.confirm) {
  //         this.getOutLogin();
  //       console.log('用户点击确定')
  //       } else if (res.cancel) {
  //       console.log('用户点击取消')
  //       }
  //       }
  //   })
    
  // },
  //切换用户
  changeUser: function () {
    var that=this;
    var type=that.data.userinfo.verification_manage;
    if (type!=0) {
      this.getroleSwitch()
    }else{
      wx.showToast({
        title: '该用户不是部门负责人',
        icon:'none'
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '设置',
    })
    this.getuserInfo();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  }, //个人信息
  getuserInfo: function () {
    var that = this;
    var uid = wx.getStorageSync('userid');
    var param = {
      uid: uid.uid,
      user_type: uid.user_type
    }
    console.log(param);
    Api.ajax('/app/Zpersonalcenter/userInfo', param).then(res => {
      console.log(res)
      if (res.code == 200) {
        that.setData({
          userinfo: res.data
        })
      }
    })
  },
  //切换用户
  getroleSwitch: function (e) {
    var that = this;
    let uid = wx.getStorageSync('userid');
    var param = {
      uid: uid.id,
      user_type: uid.user_type,
      type: 1,
    }
    console.log(param)
    Api.ajax('/app/Zindexmanage/roleSwitch', param).then(res => {
      console.log(res)
      if (res.code == 200) {
        wx.setStorageSync('userid', res.data);
        that.setData({
          userInfo: res.data
        })
        wx.reLaunch({
          url: '/pages/index/index',
        })
      }
    })
  },
  // //退出
  // getOutLogin: function () {
  //   var that = this;
  //   let uid = wx.getStorageSync('userid')
  //   var param = {
  //     uid: uid.uid
  //   }
  //   Api.ajax('/app/Zindexmanage/outLogin', param).then(res => {
  //     console.log(res)
  //     if (res.code == 200) {
  //       wx.showToast({
  //         title: '退出成功',
  //         icon: 'none',
  //         duration: 1000
  //       })
  //     }else{
  //       wx.showToast({
  //         title: '退出失败',
  //         icon: 'none',
  //         duration: 1000
  //       })
  //     }
  //   })
  // },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})